{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/garea/index')}">区服管理</a></li>
			<li class=""><a href="{:url('admin/garea/add')}">添加区服</a></li>
			<li class="layui-this">编辑区服</li>
        </ul>
        <div class="layui-tab-content">
            <form class="layui-form" action="{:url('admin/garea/update')}" method="post">
               <div class="layui-form-item">
			    <div class="layui-inline">
                      <label class="layui-form-label">区服名称</label>
                      <div class="layui-input-inline">
                        <input type="text" name="sname" value='{$garea.sname}' lay-verify="required|title" autocomplete="off" placeholder="请输入区服名称" class="layui-input">
                      </div>
			    </div>
                <div class="layui-inline">
                  <label class="layui-form-label">游戏ID</label>
                  <div class="layui-input-inline">
                    <input type="text" name="gid" value='{$garea.gid}' lay-verify="required|number" autocomplete="off" placeholder="请输入游戏ID" class="layui-input">
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">区服ID</label>
                  <div class="layui-input-inline">
                    <input type="text" name="sid" value='{$garea.sid}' lay-verify="required|number" autocomplete="off" placeholder="请输入区服ID" class="layui-input">
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">混服ID</label>
                  <div class="layui-input-inline">
                    <input type="text" name="agent" value='{$garea.agent}' lay-verify="required|number" autocomplete="off" placeholder="请输入混服ID" class="layui-input">
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">IP地址</label>
                  <div class="layui-input-inline">
                    <input type="text" name="server_ip" value='{$garea.server_ip}' lay-verify="required|number" autocomplete="off" placeholder="请输入ip地址" class="layui-input">
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">端口号</label>
                  <div class="layui-input-inline">
                    <input type="text" name="server_port" value='{$garea.server_port}' lay-verify="required|number" autocomplete="off" placeholder="请输入端口号" class="layui-input">
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">资源地址</label>
                  <div class="layui-input-inline">
                    <input type="text" name="server_res" value='{$garea.server_res}' lay-verify="required|number" autocomplete="off" placeholder="请输入混服ID" class="layui-input">
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">开服时间</label>
                  <div class="layui-input-inline">
                    <input class="layui-input" name="open_time" id="stime" value='{$garea.open_time}' lay-verify="required|datenow" placeholder="开服时间">
                  </div>
                </div>
              {volist name="info" id="vo"}
	              <div class="layui-form-item">
	                <label class="layui-form-label">{$key}</label>
	                <div class="layui-input-block">
	                  <input type="text"  name="info[{$vo}]" value="{:unserialize($garea.info)[$vo]}"  class="layui-input" >
	                </div>
	              </div>
              {/volist}
              <div class="layui-form-item">
                <label class="layui-form-label">区服状态</label>
                <div class="layui-input-block">
                  <input type="radio" name="status" value="0" title="关闭" {if condition="$garea.status==0"} checked="checked"{/if}>
                  <input type="radio" name="status" value="1" title="开启" {if condition="$garea.status==1"} checked="checked"{/if}>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
				  <input type="hidden" name="id" value="{$garea.id}">
                  <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
              </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
layui.use('form', function(){
  var form = layui.form;
      laydate = layui.laydate;
//时间选择器
var start = laydate.render({
                    elem: '#stime',
                    type: 'datetime',
                    format: 'yyyy-MM-dd HH:mm:ss',
                    done: function(value, date, endDate) {
                        start.config.max = {
                            year: date.year,
                            month: date.month - 1,
                            date: date.date,
                            hours: date.hours,
                            minutes: date.minutes,
                            seconds: date.seconds
                        }
                    }
                });
var end = laydate.render({
                    elem: '#otime',
                    type: 'datetime',
                    format: 'yyyy-MM-dd HH:mm:ss',
                    done: function(value, date, endDate) {
                        start.config.max = {
                            year: date.year,
                            month: date.month - 1,
                            date: date.date,
                            hours: date.hours,
                            minutes: date.minutes,
                            seconds: date.seconds
                        }
                    }
                });

  
	//监听指定开关
    form.on('radio(only)', function(data){
	    if (data.value == 1){
        $('#agent').attr("disabled",false);
        $("#agent").removeClass("layui-disabled");
		}else{
        $('#agent').attr("disabled",true);
        $("#agent").addClass("layui-disabled");
		}
    });
	
    //自定义验证规则
    form.verify({
      title: function(value){
        if(value.length < 2){
          return '游戏名称至少得2个字符啊';
        }
      }
	  ,agent: function(value){
	        if (value){
		    	if(!/[0-9]$/.test(value)){
		    	    return '代理ID必须为数字';
		    	}
		    }
	    }
	  ,datenow: function(value){
		    if(!/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/.test(value)){
		        return '时间格式不正确<br>正确格式为: 2017-01-01 12:00:00 ';
		    }
	    }
    });
	  
});
	
</script>
{/block}